package util

import (
	"math/rand"
	"time"
)

func MicsSlice(origin []int64, count int) []int64 {
	tmpOrigin := make([]int64, len(origin))
	copy(tmpOrigin, origin)
	//一定要seed
	rand.Seed(time.Now().Unix())
	rand.Shuffle(len(tmpOrigin), func(i int, j int) {
		tmpOrigin[i], tmpOrigin[j] = tmpOrigin[j], tmpOrigin[i]
	})

	result := make([]int64, 0, count)
	for index, value := range tmpOrigin {
		if index == count {
			break
		}
		result = append(result, value)
	}
	return result
}

// 数组唯一
func ArrayUnique(array []uint64) []uint64 {
	result := make([]uint64, 0, len(array))
	temp := map[uint64]byte{} // 存放不重复主键
	for _, e := range array {
		if _, ok := temp[e]; !ok {
			temp[e] = 0
			result = append(result, e)
		}
	}
	return result
}
